package com.gmadmin.controller;

import com.gmadmin.common.ApiResponse;
import com.gmadmin.entity.dto.MessageInfoDto;
import com.gmadmin.entity.vo.MessageInfoVo;
import com.gmadmin.service.MessageInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangliang
 * @version 1.0
 * @date 2022/8/2 20:16
 */

@Api(tags = "通知:消息详情")
@RequestMapping("api/notify/message/info")
@RestController
public class MessageInfoController {

    private final MessageInfoService infoService;

    public MessageInfoController(MessageInfoService infoService) {
        this.infoService = infoService;
    }


    @ApiOperation("根据 msgIds查询消息详情")
    @PostMapping("listByIds")
    public ApiResponse<List<MessageInfoVo>> getInfoByMsgId(@RequestBody List<Long> msgIds) {
        List<MessageInfoVo> messageInfoVos =infoService.findInfoByMsgId(msgIds);
        return ApiResponse.ofSuccess(messageInfoVos);
    }


    @ApiOperation("新增消息通知")
    @PostMapping
    public ApiResponse<String> addMessageInfo(@RequestBody MessageInfoDto infoDto) {
        infoService.saveMessageInfoAndNotify(infoDto);
        ApiResponse<String> apiResponse = new ApiResponse<>();
        return apiResponse.ofSuccess("新增消息通知成功");
    }
}
